package easycloud.ecs.provider.model.local;

import java.io.File;
import java.util.Date;

import org.apache.commons.lang.builder.ToStringBuilder;

import easycloud.ecs.common.domain.Item;
import easycloud.ecs.common.domain.Provider;
import easycloud.ecs.common.util.Md5Utils;
import easycloud.ecs.provider.model.IStorageObjectMetadata;

public class LocalStorageObjectMetadata implements IStorageObjectMetadata {

	/**
	 * 
	 */
	private static final long serialVersionUID = 7736706383296973965L;

	private long contentLength;

	private String hash;

	private Date lastModified;

	private Item item;

	public LocalStorageObjectMetadata(File file, Item item) {
		contentLength = file.length();
		hash = Md5Utils.computeMD5Hash(file);
		lastModified = new Date(file.lastModified());
		this.item = item;
	}

	@Override
	public String getHash(Provider provider) {
		return hash;
	}

	@Override
	public Item getItem() {
		return item;
	}

	@Override
	public Date getLastModified() {
		return lastModified;
	}

	@Override
	public long getLength() {
		return contentLength;
	}

	@Override
	public String getPath() {
		return item.getPath();
	}

	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this);
	}
}
